home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
C⁄C++
/
Marathon Map Viewer
/
@Source
/
myApplication.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-06-06
|
5KB
|
168 lines
/*-----------------------------------------------------------------
Copyright ©1994 Steve Israelson
This file contains the source code for the function main(),
and the source for all the methods in the "myApplication"
class. This class handles application specific stuff, like
creating new documents.
-----------------------------------------------------------------*/
#include "myApplication.h"
#include "myDocument.h"
#include "myRegisterClasses.h"
#include "commandNumbers.h"
myApplication *theApp; // our one global variable
/*-----------------------------------------------------------------
Main entry point.
-----------------------------------------------------------------*/
void main(void)
{
// Set Debugging options
InitializeHeap(15); // Initialize Memory Manager
// Parameter is number of Master Pointer
// blocks to allocate
// Initialize standard Toolbox managers
UQDGlobals::InitializeToolbox(&qd);
new LGrowZone(200000); // Install a GrowZone function to catch
// low memory situations.
// Parameter is size of reserve memory
// block to allocated. The first time
// the GrowZone function is called,
// there will be at least this much
// memory left (so you'll have enough
// memory to alert the user or finish
// what you are doing).
// some debugging settings
gDebugThrow = debugAction_SourceDebugger;
gDebugSignal = debugAction_SourceDebugger;
// create an instance of the application class and
// assign it to our global variable
theApp = new myApplication;
theApp->Run(); // run the application
delete theApp; // by this point the application has quit, so get rid of it
}
/*-----------------------------------------------------------------
Construct a new editor application.
Registers some classes with powerplant and sets up the grow zone
to detect low memory conditions.
-----------------------------------------------------------------*/
myApplication::myApplication()
{
// Register classes for objects created from 'PPob' resources
RegisterAllPPClasses();
registerMyClasses();
LGrowZone::GetGrowZone()->StartIdling(); // start the grow zone idling
}
/*-----------------------------------------------------------------
Cleans up when the application object is destroyed.
-----------------------------------------------------------------*/
myApplication::~myApplication()
{
}
/*-----------------------------------------------------------------
When the user clicks in the menu bar, this is called to see
how the menu should be drawn. In our case, we do not want
the user opening new documents when memory is getting scarce.
-----------------------------------------------------------------*/
void myApplication::FindCommandStatus(
CommandT inCommand,
Boolean &outEnabled,
Boolean &outUsesMark,
Char16 &outMark,
Str255 outName)
{
outUsesMark = false;
switch (inCommand)
{
case cmd_Open: // do not allow the opening of more docs when mem is low.
if (LGrowZone::GetGrowZone()->MemoryIsLow())
outEnabled = false;
else
outEnabled = true;
break;
// +++ Add cases here for the commands you handle
case cmd_Nothing:
default:
LDocApplication::FindCommandStatus(inCommand, outEnabled, outUsesMark,
outMark, outName);
break;
}
}
/*-----------------------------------------------------------------
Actually handle the menu command. When we define our own menu
commands, like show/hide the tool palette, we will actually
do something here. For now let the class we inherit from handle
everything.
-----------------------------------------------------------------*/
Boolean myApplication::ObeyCommand(CommandT inCommand, void *ioParam)
{
Boolean cmdHandled = true;
switch (inCommand)
{
case cmd_Nothing:
default:
cmdHandled = LDocApplication::ObeyCommand(inCommand, ioParam);
break;
}
return cmdHandled;
}
/*-----------------------------------------------------------------
Open a new document. We do this by creating a new instance
of the "myDocument" class.
-----------------------------------------------------------------*/
void myApplication::OpenDocument(FSSpec *inMacFSSpec)
{
new myDocument(this, inMacFSSpec);
}
/*-----------------------------------------------------------------
Create a new document from scratch. Note that it is not passed
a file name when the document is created.
-----------------------------------------------------------------*/
LModelObject *myApplication::MakeNewDocument()
{
return new myDocument(this, nil);
}
/*-----------------------------------------------------------------
Allow the user to choose documents.
Puts up a standard file dialog and lets the user choose only
our file types (maps). Opens a document based on the file selected.
-----------------------------------------------------------------*/
void myApplication::ChooseDocument()
{
StandardFileReply macFileReply;
SFTypeList typeList;
UDesktop::Deactivate();
typeList[0] = editorFileType;
::StandardGetFile(nil, 1, typeList, &macFileReply);
UDesktop::Activate();
if (macFileReply.sfGood)
{
OpenDocument(&macFileReply.sfFile);
}
}